import Vue from "vue";
import Vuex from "vuex";
import apis from "@/core/api/apis";
import Router from "storejs"

Vue.use(Vuex);       //this.$store.state




export default new Vuex.Store({
  state: {
    city: "上海",
    cartList: Router.get('cartList') || [],
    temp: [],
    arr: [],
    // mainlist:[],
  },
  mutations: {
    addcart(state, data) {
      //设置开关
      var boo = true;
      //第一次不会map
      state.cartList.map((item) => {
      //重复
        if (item.ID == data.ID) {
          item.num++;
          boo = false;
        }
      })
      if (boo) {
        data.num = 1;
        state.cartList.push(data);
      }
      console.log(state.cartList)
      Router.set("cartList", state.cartList);
    },
  },
  getters: {},
  actions: {}
})
